// pages/home/vip/vip.js
 
 
import { getStorageItem } from "../../../utils/storage";
import { getSharePng } from '../../../config'
let user_name = '';
let my_invite_key =''
Page({

  /**
   * 页面的初始数据
   */
  data: {
    percent: 0,
    vip_grade: 0,
    vip_point: 0,
    user_money:{
      earning_total: 0,
    },
    vipData: { 
      needGrade: 1, 
      title: "青铜会员", 
      desc: "所有功能免费使用" 
    },
    degreeList: [
      {
        id: 1,
        img: 'https://ustatic.joymew.com/joymew-assist/home/vip/reward_1.png',
        degree: 1,
        text: '所有功能免费使用'
      },
      {
        id: 2,
        img: 'https://ustatic.joymew.com/joymew-assist/home/vip/reward_2.png',
        degree: 10,
        text: '免费发礼物'
      },
      {
        id: 3,
        img: 'https://ustatic.joymew.com/joymew-assist/home/vip/reward_3.png',
        degree: 20,
        text: '定制弹幕皮肤'
      },
      {
        id: 4,
        img: 'https://ustatic.joymew.com/joymew-assist/home/vip/reward_4.png',
        degree: 30,
        text: '定制进场特效'
      },
      {
        id: 5,
        img: 'https://ustatic.joymew.com/joymew-assist/home/vip/reward_5.png',
        degree: 40,
        text: '靓号邀请码'
      },
      {
        id: 6,
        img: 'https://ustatic.joymew.com/joymew-assist/home/vip/reward_6.png',
        degree: 50,
        text: '荣誉座驾'
      },
      {
        id: 7,
        img: 'https://ustatic.joymew.com/joymew-assist/home/vip/reward_7.png',
        degree: 60,
        text: '90%礼物收益'
      },
      {
        id: 8,
        img: 'https://ustatic.joymew.com/joymew-assist/home/vip/reward_8.png',
        degree: 70,
        text: '红包收益比例自定义'
      },
      {
        id: 9,
        img: 'https://ustatic.joymew.com/joymew-assist/home/vip/reward_9.png',
        degree: 75,
        text: '神秘大礼包'
      },
      {
        id: 10,
        img: 'https://ustatic.joymew.com/joymew-assist/home/vip/reward_10.png',
        degree: 80,
        text: '嗨喵嘉年华'
      },
      {
        id: 11,
        img: 'https://ustatic.joymew.com/joymew-assist/home/vip/reward_11.png',
        degree: 85,
        text: '嗨喵荣誉导师'
      },
      {
        id: 12,
        img: 'https://ustatic.joymew.com/joymew-assist/home/vip/reward_12.png',
        degree: 90,
        text: '嗨喵合伙人'
      },      
    ],
    taskList: [
      {
        title: '邀请好友',
        detail: '好友邀起来，经验飙到嗨',
        income: ' 经验+50',
        btn: '去邀请',
        completed: false,
        img: 'https://ustatic.joymew.com/joymew-assist/home/vip/task_1.png'
      },
      {  
        title: '使用互动',
        detail: '互动千千万，嗨喵伴永远',
        income: '经验+50',
        btn: null,
        completed: false,
        img: 'https://ustatic.joymew.com/joymew-assist/home/vip/task_2.png'
      },
      {
        title: '获得收益', 
        detail: '收益天天有，幸福到长久',
        income: ' 经验+50',
        btn: null,
        completed: false,
        img: 'https://ustatic.joymew.com/joymew-assist/home/vip/task_3.png'
      },
      {
        title: '分享教程',  
        detail: '名师与教程，成就你我他',
        income: ' 经验+50',
        btn: null,
        completed: false,
        img: 'https://ustatic.joymew.com/joymew-assist/home/vip/task_4.png'
      },      
    ],
    completed: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    user_name = getStorageItem('user_name') || '著名主持人'
    my_invite_key = getStorageItem('invite_key')

    let vipData = getStorageItem("vipData")
    let vip_point = getStorageItem("vip_point")

    // let percent = (5||vip_point) / (100||(vip_point + vipData.needGrade)) * 100
    let percent = parseFloat(vip_point) / (parseFloat(vip_point) + parseFloat(vipData.needGrade)) * 100
    

    this.setData({
      headerImgPath: getStorageItem("headerImgPath"),
      invite_pcount: getStorageItem("invite_pcount"),
      vip_grade: getStorageItem("vip_grade"),
      vip_point: vip_point,
      user_money: getStorageItem("user_money"),
      vipData: vipData,
      percent: percent,
      completed: false
    }); 
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
    return {
      title: `${user_name || ''}邀请您加入嗨喵悦动`,
      path: '/pages/regist/regist?share_invite_key=' + my_invite_key,
      // imageUrl: 'https://ustatic.hudongmiao.com/joymew-assistant/invite/invite_wx.png'
      imageUrl: getSharePng()
    }
  },
  pargressEnd(){
    this.setData({
      completed: true
    })
  }
})